package org.ddd.orderdemo.remote.service;

import org.ddd.orderdemo.domain.model.product.Product;
import org.ddd.orderdemo.remote.client.dto.ProductDto;

import java.util.ArrayList;
import java.util.List;

public class ProductRemoteServiceTranslator {


    public Product toProduct(ProductDto productDto) {

        Product product = new Product();
        product.setProductId(productDto.getProductId());
        product.setProductName(productDto.getProductName());
        product.setInventoryCount(productDto.getInventoryCount());
        product.setPrice(productDto.getPrice());

        return product;
    }

    public List<Product> toProducts(List<ProductDto> productDtos) {
        ArrayList<Product> products = new ArrayList<>();

        if (productDtos != null && !productDtos.isEmpty()){

            for (ProductDto productDto : productDtos) {
                Product product = toProduct(productDto);
                products.add(product);
            }
        }

        return products;
    }

}
